{% extends "admin/base.html" %}
{% block func_name %}
    签到点管理 <a data-toggle="modal" data-target="#newPointModal"><i class="fa fa-plus-square"></i></a>&nbsp;<a href="{{ url_for('admin.dumps_data') }}" target="_blank">下载签到数据</a>
{% endblock %}
{% block content %}

<table class="table table-dark">
  <thead>
    <tr>
      <th scope="col">id</th>
      <th scope="col">签到点名</th>
        <th scope="col">分值</th>
      <th scope="col">二维码图片</th>
      <th scope="col">操作</th>
    </tr>
  </thead>
  <tbody>
  {% for point in points %}
    <tr>
      <th scope="row">{{ point.id }}</th>
      <td>{{ point.name }}</td>
        <td>{{ point.point }}</td>
      <td>
          <img src="http://qr.liantu.com/api.php?&w=200&text={{ point.key }}" style="width:200px" alt="">
      </td>
      <td>
          <button class="btn btn-danger del-btn" data="{{ url_for('admin.delete_check_point', cid=point.id) }}">删除</button>

      </td>
    </tr>
  {% endfor %}
  </tbody>
</table>
<nav aria-label="Page navigation example">
          <ul class="pagination">
            <li class="page-item"><a class="page-link" href="{{ url_for('admin.manage_check_points', name=name, p=prev_id) }}">上一页</a></li>
           {% for i in range(1, page_count + 1) %}
            <li class="page-item"><a class="page-link" href="{{ url_for('admin.manage_check_points', name=name, p=i) }}">{{ i }}</a></li>
           {% endfor %}
            <li class="page-item"><a class="page-link" href="{{ url_for('admin.manage_check_points', name=name, p=next_id) }}">下一页</a></li>
          </ul>
        </nav>

<div class="modal fade" id="newPointModal" tabindex="-1" role="dialog" aria-labelledby="pointLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form action="" id="newPointForm">
      <div class="modal-header">
        <h5 class="modal-title" id="pointLabel">新建签到点</h5>
      </div>
      <div class="modal-body">
          <div class="form-group">
            <label for="title">签到点名</label>
            <input name="pointName" type="text" class="form-control" id="pointName" placeholder="输入签到点名">
          </div>
          <div class="form-group">
            <label for="point">签到分值</label>
            <input name="pointValue" type="number" class="form-control" id="pointValue" placeholder="输入签到分值">
          </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
        <button type="submit" class="btn btn-primary">保存</button>
      </div>
      </form>
    </div>
  </div>
</div>

{% endblock %}
{% block script %}
<script type="text/javascript">
$(function(){
    $('#newPointForm').submit(function (e) {
        e.preventDefault();
        $.post('{{ url_for("admin.manage_check_points") }}', {
            name:$("#pointName").val(),
            point:$("#pointValue").val()
        }, function (d) {
           if (d.code===200){
               location.reload()
           }else{
               alert(d.info)
           }
        }, 'json')
    })
    $(".del-btn").click(function(){
        $.post($(this).attr('data'), {}, function (d) {
            if (d.code===200){
                location.reload()
            }
        }, 'json')
    })
})
</script>
{% endblock %}